<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//this == window
			//this 代表 全局的 window 对象
			//console.dir(this);//当前this == window == 对象
			//console.log(this.outerWidth);

			//在全局window里面，定义了一个函数之后，这个函数也是属于全局的
			//function f(){
			//	console.dir(this);
			//}
			//f();
			var obj = {
				name:'abc',
				show:function (){ //匿名函数
					console.dir(this);
				}
			}
			//对象方法里面的 this = 对象本身
			//obj.show();

			var func = function (){
				var c = 10;
				this.name = 'abc';
				this.age = 22;
				this.height = 180;
				this.aaa = function(){
					console.log('111');
				}
			}
			func.prototype = { //原型
				show:function(){
					console.log('show');
				},
				eat:function(){
					console.log('eat');
				}
			}
			var func2 = new func();
			console.log('func2');
			console.dir(func2.aaa());
			//new 操作符
			//函数本身，也是一个对象
			//console.dir(func);
			//console.dir(obj);

			function square(width,height){//正方形函数
				this.w = width;
				this.h = height;
			}
			square.prototype = {
				area:function(){
					return this.w * this.h;
				}
			}
			var ff = new square(200,100);
			console.dir(ff);
			console.log(ff.__proto__ === square.prototype);

			//所有对象都有原型链
			var obj1 = {name:'ssss',age:18};
			var obj2 = {name:'kkkk'};
			console.log('--------');
			console.dir(obj1);
			obj2.__proto__ = obj1;
			console.dir(obj2);
			console.log(obj2.name);

			function String(){
				this.length = 2;
			}
		</script>
	</body>
</html>